/* eslint-disable */
import IndexService from '@/api/index'
import Index2Component from '../index2/index2.vue'
import PaginationTable from '@/components/paginationTable/paginationTable.vue'
export default {
      components: {PaginationTable},
      data() {
        return {
          html: '<el-button type="primary">主要按钮</el-button>',
          list: [],
          columns: [
            {
              prop: 'id',
              label: '编号',
              width: 60
            },
            {
              prop: 'title',
              label: '标题',
              formatter: (row, column, cellValue) => {
                return `<span style="color: #999;">${row.title}</span>`
              }
            },
            {
              prop: 'state',
              label: '状态',
              render: (h, params) => {
                let type = params.row.state === 0 ? 'success' : params.row.state === 1 ? 'info' : 'danger'
                let title = params.row.state === 0 ? '安全' : params.row.state === 1 ? '正常' : '危险'
                return (<div>
                            <el-tag type={type}>{title}</el-tag>
                            <el-button type="warning" icon="el-icon-edit">{title}</el-button>
                        </div>)
              }
            },
            {
              prop: 'date',
              label: '发布时间',
              render: (h, params) => {
                return (
                  <el-button type="text" nativeOnClick={() => {
                    this.call(params)
                  }}>{params.row.date}</el-button>
                )
              }
            }
          ], // 需要展示的列
          operates: {
            width: 200,
            fixed: 'right',
            list: [
              {
                label: '删除',
                type: 'danger',
                icon: 'el-icon-delete',
                method: (row, index) => {
                  this.handleDel(row, index)
                }
              }
            ]
          }, // 操作按钮组
          pagination: {
            show: true,
            total: 0,
            pageNum: 1,
            pageSize: 15
          }, // 分页参数
          options: {
            index: false, //序号
            mutiSelect: true, //序号
            initTable: true, // 是否一进来就加载表格数据
          } // table 的参数
        }
      },
      methods: {
        getList() {
          console.log('fetch data...')
          let param = {
              pageIndex: this.pagination.pageNum,
              pageSize: this.pagination.pageSize
          }
          this.options.loading = true
          IndexService.getList(param)
            .then(res => {
              if(res.success) {
                  this.pagination.total = res.total
                  this.list = res.rows
              }
            }).finally(() => {
              this.options.loading = false
            })
        },
        // 删除
        handleDel(row, index) {
          console.log(' index:', index)
          console.log(' row:', row)
        },
        call(params) {
          this.$message(`click call ${params.row.date}`)
        },
        clickBtn() {
            let instance = this.$dialog.show(Index2Component,{title:'标题'})
            instance.onDidClose = data => {
              console.log(data)
            };
        }
      }
    }